package com.kylin.common.weixin.miniapp;

import com.alibaba.fastjson2.JSONObject;
import com.kylin.common.weixin.util.WxRequest;
import org.springframework.util.StringUtils;

/**
 * 获取手机号码服务
 * @author wuhao
 * @version 1.0 - 2021/12/17
 */
public class PhoneNumberService {
    /**
     * 获取手机号接口地址
     */
    private static final String ACCESS_TOKEN_URL = "/wxa/business/getuserphonenumber";

    /**
     * 获取用户手机号
     * @param accessToken 接口调用凭证
     * @param code 授权code
     * @return eg.{"access_token":"ACCESS_TOKEN","expires_in":7200}
     * @version 1.0  by wuhao at 2019-03-04
     */
    public static JSONObject getUserPhoneNumber(String accessToken, String code){
        String url = ACCESS_TOKEN_URL;
        if(StringUtils.hasText(accessToken)) {
            url += "?access_token=" + accessToken;
        }
        JSONObject params = new JSONObject();
        params.put("code", code);
        return WxRequest.post(url,params.toJSONString());
    }

}
